~ chicken-core (master) /manual/Module (scheme eval)


 1[[tags: manual]]
 2[[toc:]]
 3
 4== Module (scheme eval)
 5
 6This module provides R7RS procedures to evaluate expressions dynamically.
 7
 8=== environment
 9
10<procedure>(environment LIST ...)</procedure>
11
12This procedure returns a specifier for the environment that
13results by starting with an empty environment and then
14importing each list, considered as an import set, into it.
15(See section 5.6 of R7RS for a description of import sets.) The
16bindings of the environment represented by the specifier
17are immutable, as is the environment itself.
18
19=== eval
20
21<procedure>(eval EXPR-OR-DEF [ENVIRONMENT-SPECIFIER])</procedure>
22
23If EXPR-OR-DEF is an expression, it is evaluated in the specified environment and its values are returned. If it is a definition, the specified identifier(s) are defined in the specified
24environment, provided the environment is not immutable.
25
26The {{ENVIRONMENT-SPECIFIER}} is optional, and if not provided it
27defaults to the value of {{(interaction-environment)}}.  This is a
28CHICKEN extension to R7RS, which, though strictly nonportable, is very
29common among Scheme implementations.
30
31 (eval '(* 7 3) (environment '(scheme base))) 
32     ==> 21
33 
34 (let ((f (eval '(lambda (f x) (f x x))
35                (null-environment 5))))
36   (f + 10))
37     ==> 20
38
39---
40Previous: [[Module (scheme file)]]
41
42Next: [[Module (scheme inexact)]]
Trap